import { Action, createReducer, on } from "@ngrx/store";
import * as themeActions from "../actions/theme.action";

export interface State {
  theme: "primary" | "warn" | "basic";
  id: number;
}

export const initialState: State = {
  theme: "primary",
  id: 0
};

const countReducer = createReducer(
  initialState,
  on(themeActions.setTheme, (state, { propTheme }) => ({
    ...state,
    theme: propTheme
  })),
  on(themeActions.setThemeID, (state, { propThemeID }) => ({
    ...state,
    id: propThemeID
  }))
);

export function reducer(state: State | undefined, action: Action) {
  return countReducer(state, action);
}
